﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using C.Unite;
using C.Entities;
using ChanExt;
using MySoft.Data;
using System.Text;
using LitJson;

namespace ArtLand.OA.Project.SystemMgr
{
    public partial class SysMessage : CommonPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //btnNew.OnClientClick = Window1.GetShowReference("Proj_TaskAdd.aspx", "发起新任务");

                BindGrid(GetWhere());
            }
        }


        #region BindGrid
        private void BindGrid(WhereClip wc)
        {
            Grid1.RecordCount = TbsDbSession.Default.From<HR_MesSendLogs>().Where(wc).Count();

            List<HR_MesSendLogs> items = TbsDbSession.Default.From<HR_MesSendLogs>().Where(wc).OrderBy(HR_MesSendLogs._.ID.Desc).Page(Grid1.PageSize, (Grid1.PageIndex + 1)).ToList();

            // 3.绑定到Grid
            Grid1.DataSource = items;
            Grid1.DataBind();
        }



        protected void Grid1_PageIndexChange(object sender, ChanExt.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid(GetWhere());
        }

        public WhereClip GetWhere()
        {
            WhereClip wc = WhereClip.All;
            wc = wc && HR_MesSendLogs._.Uid == CookInfo.EEmpID();
            if (btn1.Pressed)
                wc = wc && HR_MesSendLogs._.IsRead == false;
            if (Button1.Pressed)
                wc = wc && HR_MesSendLogs._.IsRead == true;
            //if (!string.IsNullOrEmpty(Request["did"]))
            //{
            //    wc = wc && Adm_BASICD._.BATYPE == int.Parse(Request["did"]);
            //}
            //if (!String.IsNullOrEmpty(ttbxMyBox2.Text))
            //{
            //    wc = wc && (Proj_Task._.Proj_NO.Contain(ttbxMyBox2.Text) || Proj_Task._.Task_Implement.Contain(ttbxMyBox2.Text) || Proj_Task._.Task_Organiser.Contain(ttbxMyBox2.Text));
            //}
            //if (!string.IsNullOrEmpty(Request["s"]))
            //{

            //    List<VI_C8> listc = TbsDbSession.Default.From<VI_C8>().Where(VI_C8._.C == 1).ToList();
            //    int[] listint = (from p in listc select p.ID).ToArray();
            //    if (listint.Length > 0)
            //        wc = wc && Proj_Task._.ID.SelectIn<int>(listint);
            //    else
            //    {
            //        PageContext.RegisterStartupScript("top.__doPostBack('hid_btn', '');top.RemoveT('M_wainttask');");
            //    }
            //}
            //if (!string.IsNullOrEmpty(Request["t"]))
            //{

            //    List<VI_C1> listc = TbsDbSession.Default.From<VI_C1>().Where(VI_C1._.C == 0).ToList();
            //    int[] listint = (from p in listc select p.ID).ToArray();
            //    if (listint.Length > 0)
            //        wc = wc && Proj_Main._.ID.SelectIn<int>(listint);
            //}
            return wc;
        }
        #endregion

        protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
        {
            //string stuts = "";
            //string st = e.Values[7].ToString();
            //switch (st)
            //{
            //    case "0":
            //        stuts = "未进行";
            //        break;
            //    case "1":
            //        stuts = "进行中";
            //        break;
            //    case "2":
            //        stuts = "已完成";
            //        break;
            //    case "10":
            //        stuts = "取消";
            //        break;
            //}
            //e.Values[7] = stuts;
            //string color = e.Values[7].ToString();
            //string bold = e.Values[8].ToString();
            //if (bold == "True")
            //    bold = "bold";
            //else
            //    bold = "";
            //string title = "<span style=\"color:{0};font-weight:{1}\">" + e.Values[0] + "</span>";
            //title = string.Format(title, color, bold);
            //e.Values[0] = title;
            //e.Values[7] = "<a href=\"javascript:;\" onclick=\"TabView('/AfterSale/ASale_RePairChange.aspx?id=" + e.Values[7] + "', 'tab_wxadd', '修改维修记录', '/icon/comment_edit.png');\"><img src=\"/icon/comment_edit.png\" /></a>";
        }

        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            //int id = int.Parse(Grid1.DataKeys[e.RowIndex][0].ToString());
            //if (e.CommandName == "Del")
            //{
            //    Proj_Task pm = new Proj_Task();
            //    pm.ID = id;
            //    pm.Attach();
            //    pm.Task_State = 10;
            //    TbsDbSession.Default.Update<Proj_Task>(pm);
            //    //TbsDbSession.Default.Delete<Proj_Main>(Proj_Main._.ID == id);
            //    Alert.ShowInTop("任务已经取消！");
            //    BindGrid(GetWhere());
            //}
        }

        protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
        {
            string page=Grid1.Rows[e.RowIndex].Values[3].ToString();
            int id =int.Parse(Grid1.Rows[e.RowIndex].Values[4].ToString());
            HR_MesSendLogs me = new HR_MesSendLogs();
            me.ID = id;
            me.Attach();
            me.IsRead = true;
            TbsDbSession.Default.Update<HR_MesSendLogs>(me);
            BindGrid(GetWhere());
            FormInfo.ShowTab(page, "zhuanzheng", "", "转正处理");
            //string n = Grid1.Rows[e.RowIndex].Values[5].ToString();
            //if (n == "取消")
            //{

            //}
            //else
            //{
            //    int id = int.Parse(Grid1.DataKeys[e.RowIndex][0].ToString());
            //    PageContext.RegisterStartupScript(Window1.GetShowReference("Pro_TaskAdd.aspx?id=" + id, "修改"));
            //}
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //FormInfo.GridEdit(Grid1, Window1, "Pro_TaskAdd.aspx");
            //BindGrid(GetWhere());
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

            //int[] list = Grid1.SelectedRowIndexArray;
            //if (list.Length > 0)
            //{
            //    int del = 0;
            //    foreach (int item in list)
            //    {
            //        int index = item;
            //        int id = int.Parse(Grid1.DataKeys[index][0].ToString());
            //        Proj_Task pm = new Proj_Task();
            //        pm.ID = id;
            //        pm.Attach();
            //        pm.Task_State = 10;
            //        del = TbsDbSession.Default.Update<Proj_Task>(pm);
            //    }
            //    if (del > 0)
            //        Alert.Show("任务已经取消！");
            //}
            //else
            //    Alert.Show("请选择一项进行取消处理！");

            //BindGrid(GetWhere());
        }

        protected void btnContatAdd_Click(object sender, EventArgs e)
        {
            //string ok = Window1.GetShowReference("Pro_TaskAdd.aspx", "发起任务"); ;

            //PageContext.RegisterStartupScript(ok);
        }

        protected void Grid1_RowSelect(object sender, GridRowSelectEventArgs e)
        {

            //string n = Grid1.Rows[e.RowIndex].Values[7].ToString();
            //if (n == "取消")
            //{
            //    Button1.Enabled = false;
            //    Button2.Enabled = false;
            //}
            //else
            //{
            //    Button1.Enabled = true;
            //    Button2.Enabled = true;
            //}
        }

        protected void btn_TaskAdd_Click(object sender, EventArgs e)
        {
            //PageContext.RegisterStartupScript(Window1.GetShowReference("/Project/Pro_TaskAdd.aspx?mtype=1"));
        }

        protected void btn_TaskView_Click(object sender, EventArgs e)
        {

        }

        protected void btn1_Click(object sender, EventArgs e)
        {
            BindGrid(GetWhere());
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            BindGrid(GetWhere());
        }
    }
}